package com.example.yigoumall.mapper;

import com.example.yigoumall.entity.News;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface NewsMapper {
    
    @Select("SELECT * FROM easybuy_news")
    List<News> findAll();
    
    @Select("SELECT * FROM easybuy_news WHERE id = #{id}")
    News findById(Integer id);
    
    @Select("SELECT * FROM easybuy_news WHERE title LIKE CONCAT('%', #{title}, '%')")
    List<News> findByTitle(String title);
    
    @Insert("INSERT INTO easybuy_news(title, content, createTime) VALUES(#{title}, #{content}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(News news);
    
    @Update("UPDATE easybuy_news SET title=#{title}, content=#{content} WHERE id=#{id}")
    int update(News news);
    
    @Delete("DELETE FROM easybuy_news WHERE id=#{id}")
    int deleteById(Integer id);
}